<?php
/**
* @package Scribble
* @subpackage Plugin
*/
use Buan\AutoLoader;
use Buan\Config;
use Buan\ExtensionManager;
use Buan\UrlCommand;
class SpSpider extends ScribblePlugin implements IScribblePlugin {

	/**
	* Environment-agnostic configuration.
	*
	* @return void
	*/
	public function configure() {

		// Configuration
		Config::set('ext.Scribble.plugin.SpSpider.dir.views', dirname(__FILE__).'/views');

		// Add classpaths
		AutoLoader::addClassPath(dirname(__FILE__).'/lib');

		// Setup controllers
		$this->setupControllers(dirname(__FILE__).'/controllers',
			array("/sp-spider", ScribbleEnvironment::ADMIN)
		);
	}

	/**
	* Configure ADMIN environment.
	*
	* @return void
	*/
	private function configureAdmin() {

		// Add admin menus
		$ext = ExtensionManager::get('Scribble');
		$ext->addAdminMenuTemplate(dirname(__FILE__).'/admin-menus.tpl.php');

		// Add stats widget to dashboard
		$w = new SpSpiderStatsWidget();
		$ext->registerDashboardWidget($w);
	}

	/**
	* Environment-specific configuration.
	*
	* @return void
	*/
	public function configureEnvironment($e) {
		if($e===ScribbleEnvironment::ADMIN) {
			return $this->configureAdmin();
		}
		else {
			return $this->configureFrontend();
		}
	}

	/**
	* Configure FRONTEND environment.
	*
	* @return void
	*/
	private function configureFrontend() {
	}

	/**
	* Return information URL.
	*
	* @return string
	*/
	public function getInformationUrl() {
		return "http://www.scribblecms.co.uk/plugins/sp-spider";
	}

	/**
	* Patch.
	*
	* @param string
	* @param string
	* @return void
	*/
	public function patchVersion($to, $from) {
	}

	/**
	* Test version compatibility.
	*
	* @param string
	* @param string
	* @return bool
	*/
	public function testVersionCompatibility($to, $from) {
		$to = (float)$to;
		$from = (float)$from;
		if($to<=0.1) {
			return TRUE;
		}
		return FALSE;
	}
}
?>
